﻿#region License

// Copyright (c) 2011, Matt Holmes
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without modification, are permitted provided 
// that the following conditions are met:
// 
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the 
//   following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
//   the following disclaimer in the documentation and/or other materials provided with the distribution.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
// OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

using System;
using System.Runtime.InteropServices;

namespace SkyrimTweaker.Common {
	public static class NativeInterop {
		#region Fields

		public const UInt32 SWP_FRAMECHANGED = 0x0020; /* The frame changed: send WM_NCCALCSIZE */
		public const UInt32 SWP_HIDEWINDOW = 0x0080;
		public const UInt32 SWP_NOACTIVATE = 0x0010;
		public const UInt32 SWP_NOCOPYBITS = 0x0100;
		public const UInt32 SWP_NOMOVE = 0x0002;
		public const UInt32 SWP_NOOWNERZORDER = 0x0200; /* Don’t do owner Z ordering */
		public const UInt32 SWP_NOREDRAW = 0x0008;
		public const UInt32 SWP_NOSENDCHANGING = 0x0400; /* Don’t send WM_WINDOWPOSCHANGING */
		public const UInt32 SWP_NOSIZE = 0x0001;
		public const UInt32 SWP_NOZORDER = 0x0004;
		public const UInt32 SWP_SHOWWINDOW = 0x0040;

		public const UInt32 TOPMOST_FLAGS =
			SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSENDCHANGING;

		public static readonly IntPtr HWND_BOTTOM = new IntPtr (1);
		public static readonly IntPtr HWND_NOTOPMOST = new IntPtr (-2);
		public static readonly IntPtr HWND_TOP = new IntPtr (0);
		public static readonly IntPtr HWND_TOPMOST = new IntPtr (-1);

		#endregion

		#region Public Methods

		[DllImport ("uxtheme.dll", ExactSpelling = true)]
		public static extern int DrawThemeBackground (IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, ref RECT pRect, ref RECT pCliPRect);

		[DllImport ("user32.dll")]
		public static extern IntPtr GetWindowDC (IntPtr hWnd);

		[DllImport ("user32.dll")]
		[return: MarshalAs (UnmanagedType.Bool)]
		public static extern bool GetWindowRect (IntPtr hWnd, out RECT lpRect);

		[DllImport ("uxtheme.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
		public static extern IntPtr OpenThemeData (IntPtr hWnd, string classList);

		[DllImport ("user32.dll")]
		public static extern bool SetWindowPos (IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

		#endregion

		#region Nested type: RECT

		[StructLayout (LayoutKind.Sequential)]
		public struct RECT {
			public int Left;
			public int Top;
			public int Right;
			public int Bottom;
		}

		#endregion
	}
}
